<?php

class Vnf_Controller_Admin_Action extends Vnf_Controller_Action {
    public function init()
	{
        
        $defaultNamespace = new Zend_Session_Namespace('Default');
        if (!isset($defaultNamespace->lang)) {
            $lang = $defaultNamespace->lang = 'en';
        } else {
            $lang = $defaultNamespace->lang;
        }
        $lang_param = $this->getParam('lang', null);
        
        if ($lang_param) {
            $lang = $defaultNamespace->lang = $lang_param;
        }
        $this->view->lang = $lang;
        
		parent::init();
		$this->initAuth();
	}

    public function initAuth()
	{
		$request = $this->_request;
		if (!Zend_Auth::getInstance()->hasIdentity())
		{
		    if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])
		    && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
		        echo "location.href = '".BASE_URL."/index/authentication/';";
		        die();
		    }
		    $this->_redirect("authentication/login");
		}
	}
}